import http from '@/utils/http'

interface BasicParams {
  dtoName: string // 参考后端接口文档
  queryId: string // 参考confluence上的页面需求SQL标识
  version: string // 参考confluence上的页面需求SQL版本号
  menuName: string // 菜单的标识，与菜单管理配置保持一致
  usage: string // 接口后缀，标识用途
  export: boolean // 标志导出状态
}
interface ConfirmParams {
  eventComment: string // 参考后端接口文档
  eventUser: string // 当前登录账号
  menuName: string // 菜单的标识，与菜单管理配置保持一致
  usage: string // 接口后缀，标识用途
}

/*
  eg./ims-tworkgz-service/viewCstHistory/getCstHistory
*/
export function getList(data: BasicParams): Promise<any> {
  const { menuName, usage, export: e = false } = data
  return http.request({
    url: `/ims-tworkgz-service/${menuName}/${usage}`,
    method: 'POST',
    responseType: e ? 'blob' : 'json',
    data
  })
}
/** 获取operation */
export function getOperation({
  shopId, version = '80017', route, productId, productVer, routeVer
}:
  { shopId: string, version: string, route: string, productId: string, productVer: string, routeVer: string }): Promise<any> {
  const data = {
    dtoName: 'OperationDTO',
    queryId: 'GetProcessOperationList',
    version,
    shopId,
    route,
    productId,
    productVer,
    routeVer
  }
  return http.request({
    url: '/ims-tworkgz-service/common/getOperation',
    method: 'POST',
    data
  })
}
/** 获取shopId */
export function getShopId({ userGroup }: { userGroup: string }): Promise<any> {
  const data = {
    dtoName: 'ShopIdDTO',
    queryId: 'GetFactoryList',
    version: '80001',
    resourceState: 'InService',
    shopType: 'ProductionFactory',
    userGroup
  }
  return http.request({
    url: '/ims-tworkgz-service/common/getShopId',
    method: 'POST',
    data
  })
}

/** 获取BayId */
export function getBayId({ shopId, version = '80002' }: { shopId: string, version: string }): Promise<any> {
  const data = {
    dtoName: 'BayIdDTO',
    queryId: 'GetAreaList',
    version,
    resourceState: 'InService',
    areaType: 'ProductionArea',
    shopId
  }
  return http.request({
    url: '/ims-tworkgz-service/common/getBayId',
    method: 'POST',
    data
  })
}

/** 获取EQId */
export function getEqpId({
  bayId, shopId, version = '80022'
}: { bayId: string, version: string, shopId: string }): Promise<any> {
  const data = {
    dtoName: 'EqpIdDTO',
    queryId: 'GetMachineList',
    eqpDetailType: 'MAIN',
    eqpType: 'ProductionMachine',
    version,
    bayId,
    shopId
  }
  return http.request({
    url: '/ims-tworkgz-service/common/getEqpId',
    method: 'POST',
    data
  })
}

/** 获取 product type信息 */
export function getProductType(): Promise<any> {
  const data = {
    dtoName: 'ProductTypeDTO',
    queryId: 'GetEnumDefValueList',
    version: '80001',
    enumName: 'ProductionType',
    usage: 'ProductionType'
  }
  return http.request({
    url: '/ims-tworkgz-service/common/getProductType',
    method: 'POST',
    data
  })
}

/** 获取 product id信息 */
export function getProductId({
  productType = '', shopId, version = '80002', queryId = 'GetProductSpecList'
}: { version: string, productType: string, shopId: string, queryId: string }): Promise<any> {
  const data = {
    dtoName: 'ProductIdDTO',
    queryId,
    activeState: '',
    version,
    productType,
    shopId
  }
  return http.request({
    url: '/ims-tworkgz-service/common/getProductId',
    method: 'POST',
    data
  })
}

/** 获取owner type信息 */
export function getOwnerType(): Promise<any> {
  const data = {
    dtoName: 'OwnerTypeDTO',
    queryId: 'GetEnumDefValueList',
    version: '80004',
    usage: 'ProductionType'
  }
  return http.request({
    url: '/ims-tworkgz-service/common/getOwnerType',
    method: 'POST',
    data
  })
}

/** 获取owner信息 */
export function getOwnerId({ ownerType, shopId, version = '80005' }: { ownerType: string, shopId: string, version: string }): Promise<any> {
  const data = {
    dtoName: 'OwnerDTO',
    queryId: 'GetOwnerList',
    version,
    usage: 'ProductionType',
    ownerType,
    shopId
  }
  return http.request({
    url: '/ims-tworkgz-service/common/getOwner',
    method: 'POST',
    data
  })
}

/** 获取cstSpec信息 */
export function getCstSpec({ shopId, queryId = 'GetDurableSpecList', version = '80002' }: { shopId: string, queryId: string, version: string }): Promise<any> {
  const data = {
    dtoName: 'CstSpecDTO',
    queryId,
    durableType: 'Carrier',
    version,
    shopId
  }
  return http.request({
    url: '/ims-tworkgz-service/common/getCstSpec',
    method: 'POST',
    data
  })
}

/** 获取cstId信息 */
export function getCstId({ cstSpec, shopId }: { cstSpec: string, shopId: string }): Promise<any> {
  const data = {
    dtoName: 'OwnerDTO',
    queryId: 'GetDurableList',
    version: '81014',
    shopId,
    cstSpec
  }
  return http.request({
    url: '/ims-tworkgz-service/common/getCstId',
    method: 'POST',
    data
  })
}

/** 获取MaterialType信息 */
export function getMaterialType({ queryId = 'GetEnumDefValueList', version = '80001', shopId }: { queryId: string, version: string, shopId: string }): Promise<any> {
  const data = {
    dtoName: 'MaterialTypeDTO',
    enumName: 'ConsumableType',
    queryId,
    version,
    shopId
  }
  return http.request({
    url: '/ims-tworkgz-service/common/getMaterialType',
    method: 'POST',
    data
  })
}

/** 获取State信息 */
export function getState({ shopId }: { shopId: string }): Promise<any> {
  const data = {
    dtoName: 'StateDTO',
    queryId: 'GetEnumDefValueList',
    version: '80001',
    enumName: 'CellMaterialState',
    usage: 'State',
    shopId
  }
  return http.request({
    url: '/ims-tworkgz-service/common/getState',
    method: 'POST',
    data
  })
}
/** 获取 unit id信息 */
export function getUnitId({ eqpId, version = '80014' }: { eqpId: string, version: string }): Promise<any> {
  const data = {
    dtoName: 'UnitIdDTO',
    queryId: 'GetMachineList',
    version,
    eqpId
  }
  return http.request({
    url: '/ims-tworkgz-service/common/getUnitId',
    method: 'POST',
    data
  })
}

/** 获取 portId信息 */
export function getPortId({ eqpId }: { eqpId: string }): Promise<any> {
  const data = {
    dtoName: 'PortIdDTO',
    queryId: 'GetPortList',
    version: '80002',
    eqpId
  }
  return http.request({
    url: '/ims-tworkgz-service/common/getPortId',
    method: 'POST',
    data
  })
}

/** 获取 TFTProductSpec信息 */
export function getTftProductSpec(): Promise<any> {
  const data = {
    dtoName: 'TftProductSpecDTO',
    queryId: 'GetProductSpecList',
    version: '80056'
  }
  return http.request({
    url: '/ims-tworkgz-service/common/getTFTProductSpec',
    method: 'POST',
    data
  })
}
/** 获取 cf product spec信息 */
export function getCfProductSpec({ tftProductSpec, tftProductSpecVersion }: { tftProductSpec: string, tftProductSpecVersion: string }): Promise<any> {
  const data = {
    dtoName: 'CfProductSpecDTO',
    queryId: 'GetProductSpecList',
    version: '80057',
    tftProductSpec,
    tftProductSpecVersion
  }
  return http.request({
    url: '/ims-tworkgz-service/common/getCfProductSpec',
    method: 'POST',
    data
  })
}

/** 获取 Glass ID 信息 */
export function getGlassId({ cstId }: { cstId: string }): Promise<any> {
  const data = {
    dtoName: 'GlassIdDTO',
    queryId: 'GetProductList',
    version: '80010',
    cstId
  }
  return http.request({
    url: '/ims-tworkgz-service/common/getGlassId',
    method: 'POST',
    data
  })
}

/** 获取MaskSpec信息 */
export function getMaskSpec({ shopId }: { shopId: string }): Promise<any> {
  const data = {
    dtoName: 'MaskSpecDTO',
    durableType: 'Mask',
    queryId: 'GetDurableSpecList',
    version: '80002',
    shopId
  }
  return http.request({
    url: 'ims-tworkgz-service/common/getMaskSpec',
    method: 'POST',
    data
  })
}

/** 获取MaskName信息 */
export function getMaskName({ shopId, maskSpec }: { shopId: string, maskSpec: string }): Promise<any> {
  const data = {
    dtoName: 'MaskNameDTO',
    durableType: 'Mask',
    queryId: 'GetDurableList',
    maskSpecVersion: '00001',
    version: '80014',
    maskSpec,
    shopId
  }
  return http.request({
    url: 'ims-tworkgz-service/common/getMaskName',
    method: 'POST',
    data
  })
}

/** 获取MaskState信息 */
export function getMaskState({ enumName = '', usage = '' }: { enumName: string, usage: string }): Promise<any> {
  const data = {
    dtoName: 'MaskStateDTO',
    queryId: 'GetEnumDefValueList',
    version: '80002',
    enumName,
    usage
  }
  return http.request({
    url: 'ims-tworkgz-service/common/getMaskState',
    method: 'POST',
    data
  })
}

/** 获取CaseName信息 */
export function getCaseName({ shopId }: { shopId: string }): Promise<any> {
  const data = {
    dtoName: 'CaseNameDTO',
    queryId: 'GetMaskCaseList',
    version: '80016',
    maskName: '',
    shopId
  }
  return http.request({
    url: 'ims-tworkgz-service/common/getCaseName',
    method: 'POST',
    data
  })
}

/** 获取lineName/eqid信息 */
export function getLineName({
  detailMachineType, superMachineId, bayId, shopId
}: { detailMachineType: string, superMachineId: string, bayId: string, shopId: string }): Promise<any> {
  const data = {
    dtoName: 'LineNameDTO',
    queryId: 'GetMachineList',
    version: '80097',
    detailMachineType,
    superMachineId,
    bayId,
    shopId
  }
  return http.request({
    url: '/ims-tworkgz-service/cellPpkWipInfo/getLineNameOrEqId',
    method: 'POST',
    data
  })
}

/** 获取 Setting COde 信息 */
export function getSettingCode({ type, queryId = 'GetSettingCodeList' }: { type: string, queryId: string }): Promise<any> {
  const data = {
    dtoName: 'SettingCodeDTO',
    queryId,
    version: '80001',
    type
  }
  return http.request({
    url: '/ims-tworkgz-service/common/getSettingCode',
    method: 'POST',
    data
  })
}
/** 获取 Sub EQP Type 信息 */
export function getSubEqpType({ bayId }: { bayId: string }): Promise<any> {
  const data = {
    dtoName: 'SubEqpTypeDTO',
    queryId: 'GetMachineTypeList',
    version: '80002',
    bayId
  }
  return http.request({
    url: '/ims-tworkgz-service/common/getSubEqpTypeList',
    method: 'POST',
    data
  })
}

/** 获取 Deparment 信息 */
export function getDepartment({ queryId = 'GetEnumDefValueList' }: { queryId: string }): Promise<any> {
  const data = {
    dtoName: 'DepartmentDTO',
    queryId,
    version: '80001',
    enumName: 'Department',
    usage: 'System'
  }
  return http.request({
    url: '/ims-tworkgz-service/common/getDepartmentList',
    method: 'POST',
    data
  })
}

/** 获取 Control Owner 信息 */
export function getControlOwner({ enumName = '', usage = '' }: { enumName: string, usage: string }): Promise<any> {
  const data = {
    dtoName: 'ControlOwnerDTO',
    queryId: 'GetEnumDefValueList',
    version: '80001',
    enumName,
    usage
  }
  return http.request({
    url: '/ims-tworkgz-service/common/getControlOwner',
    method: 'POST',
    data
  })
}

/** 获取 Control Site 信息 */
export function getControlSite({ enumName = '', usage = '' }: { enumName: string, usage: string }): Promise<any> {
  const data = {
    dtoName: 'ControlSiteDTO',
    queryId: 'GetEnumDefValueList',
    version: '80002',
    enumName,
    usage
  }
  return http.request({
    url: '/ims-tworkgz-service/common/getControlSite',
    method: 'POST',
    data
  })
}

/** 获取 CST State 信息 */
export function getCstState({ enumName = '', usage = '' }: { enumName: string, usage: string }): Promise<any> {
  const data = {
    dtoName: 'CSTStateDTO',
    queryId: 'GetEnumDefValueList',
    version: '80001',
    enumName,
    usage
  }
  return http.request({
    url: '/ims-tworkgz-service/common/getCSTState',
    method: 'POST',
    data
  })
}

/** 获取 Transfer State 信息 */
export function getTransferState(): Promise<any> {
  return http.request({
    url: '/ims-tworkgz-service/common/getTransferState',
    method: 'POST'
  })
}

/** 获取 Pitch 信息 */
export function getPitch({ enumName = '', usage = '' }: { enumName: string, usage: string }): Promise<any> {
  const data = {
    dtoName: 'PitchDTO',
    queryId: 'GetEnumDefValueList',
    version: '80001',
    enumName,
    usage
  }
  return http.request({
    url: '/ims-tworkgz-service/common/getPitch',
    method: 'POST',
    data
  })
}

/** 获取 Part No 信息 */
export function getPartNo({ shopId, materialType }: { shopId: string, materialType: string }): Promise<any> {
  const data = {
    dtoName: 'PartNoDTO',
    queryId: 'GetConsumableSpecList',
    version: '80001',
    shopId,
    materialType
  }
  return http.request({
    url: '/ims-tworkgz-service/common/getPartNo',
    method: 'POST',
    data
  })
}
/** confirm操作 */
export function confirm(data: ConfirmParams): Promise<any> {
  const { menuName, usage } = data
  return http.request({
    url: `/ims-tworkgz-service/${menuName}/${usage}`,
    method: 'POST',
    data
  })
}
/** 获取 routeList 信息 */
export function getRouteList({
  productId, productVersion, shopId, version = '80022',
  queryId = 'GetProcessFlowList'
}: {
  productId: string, productVersion: string, shopId: string, version: string, queryId: string
}): Promise<any> {
  const data = {
    dtoName: 'RouteDTO',
    queryId,
    productId,
    productVersion,
    shopId,
    version
  }
  return http.request({
    url: '/ims-tworkgz-service/common/getRouteList',
    method: 'POST',
    data
  })
}
/** 获取 zone id 信息 */
export function getZoneId({ eqpId, shopId }: { eqpId: string, shopId: string }): Promise<any> {
  const data = {
    dtoName: 'ZoneIdDTO',
    queryId: 'GetMachineList',
    version: '80014',
    shopId,
    eqpId
  }
  return http.request({
    url: '/ims-tworkgz-service/common/getZoneId',
    method: 'POST',
    data
  })
}
/** 获取 ReasonCode 信息 */
export function getReasonCode({ shopId, version = '80018' }: { shopId: string, version: string }): Promise<any> {
  const data = {
    dtoName: 'ReleaseCstReasonCodeDTO',
    queryId: 'GetReasonCodeList',
    reasonCodeType: 'CSTHold',
    shopId,
    version
  }
  return http.request({
    url: '/ims-tworkgz-service/common/getReasonCodeList',
    method: 'POST',
    data
  })
}

/**  获取 EnumInfo(settingCode) */
export function getEnumInfo({ enumName }: { enumName: string }): Promise<any> {
  const data = {
    dtoName: 'EnumInfoDTO',
    queryId: 'GetEnumDefValueList',
    usage: 'system',
    version: '80001',
    enumName
  }
  return http.request({
    url: '/ims-tworkgz-service/common/getEnumInfo',
    method: 'POST',
    data
  })
}

/** trackIn操作 */
export function trackIn(data: ConfirmParams): Promise<any> {
  return http.request({
    url: '/ims-tworkgz-service/trackIn',
    method: 'POST',
    data
  })
}

/** 获取glassType */
export function getGlassType({ productSpecName, productSpecType, queryId = 'GetProductSpecList' }: { productSpecName: string, productSpecType: string, queryId: string }): Promise<any> {
  const data = {
    dtoName: 'GlassTypeDTO',
    productSpecName,
    productSpecType,
    queryId,
    version: '90005'
  }
  return http.request({
    url: '/ims-tworkgz-service/common/getGlassType',
    method: 'POST',
    data
  })
}

/** 获取 trackIn EQP Id */
export function getTrackInEqpId({ glassId, shopId }: { glassId: string, shopId: string }): Promise<any> {
  const params = {
    glassId,
    shopId
  }
  return http.request({
    url: '/ims-tworkgz-service/trackIn/getEqpId',
    method: 'get',
    params
  })
}

/** 获取 trackIn EQP Info */
export function getTrackInEqpInfo({ eqpId, shopId }: { eqpId: string, shopId: string }): Promise<any> {
  const params = {
    eqpId,
    shopId
  }
  return http.request({
    url: '/ims-tworkgz-service/trackIn/getEqpInfo',
    method: 'get',
    params
  })
}

/** 获取 trackIn protId */
export function getPort({
  areaName, shopId, eqpId, processState, pexMachineGroup
}: { areaName: string, eqpId: string, shopId: string, processState: string, pexMachineGroup: string }): Promise<any> {
  const params = {
    areaName,
    eqpId,
    processState,
    shopId,
    pexMachineGroup
  }
  return http.request({
    url: '/ims-tworkgz-service/trackIn/getPort',
    method: 'get',
    params
  })
}

/** 获取 trackIn getRecipeName */
export function getRecipe({
  operation, productId, eqpId, productVer, route, shopId
}: { operation: string, eqpId: string, productId: string, productVer: string, route: string, shopId: string }): Promise<any> {
  const params = {
    operation,
    eqpId,
    productVer,
    productId,
    route,
    shopId
  }
  return http.request({
    url: '/ims-tworkgz-service/trackIn/getRecipe',
    method: 'get',
    params
  })
}

/** 获取 Sample Type 信息 */
export function getSampleType({ enumName = '', enumValue = '' }: { enumName: string, enumValue: string }): Promise<any> {
  const data = {
    dtoName: 'SampleTypeDTO',
    queryId: 'GetEnumDefValueList',
    version: '80025',
    enumName,
    enumValue
  }
  return http.request({
    url: '/ims-tworkgz-service/common/getSampleType',
    method: 'POST',
    data
  })
}

/** 获取 getAreaList 信息 */
export function getAreaList({ areaType, resourceState, shopId }: { areaType: string, shopId: string, resourceState: string }): Promise<any> {
  const params = {
    dtoName: 'AreaListDTO',
    queryId: 'GetAreaList',
    version: '80002',
    areaType,
    resourceState,
    shopId
  }
  return http.request({
    url: '/ims-tworkgz-service/shipLot/getAreaList',
    method: 'get',
    params
  })
}

/** 获取 getFactoryList 信息 */
export function getFactoryList({ factoryType, resourceState, sourceFactoryName }: { sourceFactoryName: string, factoryType: string, resourceState: string }): Promise<any> {
  const params = {
    dtoName: 'FactoryListDTO',
    queryId: 'GetFactoryList',
    version: '80002',
    factoryType,
    resourceState,
    sourceFactoryName
  }
  return http.request({
    url: '/ims-tworkgz-service/shipLot/getFactoryList',
    method: 'get',
    params
  })
}
